package 二分查找;

/**
 * @author admin
 * @version 1.0.0
 * @ClassName 二分查找三种方式.java
 * @Description TODO
 * @createTime 2020年11月06日 10:41:00
 */
public class 二分查找三种方式 {
    public static void main(String[] args) {
        int[] nums={1,2,3,4,5,6,7,8,9,10,11,12,13,14};
        Solution solution=new  Solution();
        solution.search(nums,3);
    }

    static class Solution {
        public int search(int[] nums, int target) {
            int left=0;
            int right=nums.length;
            while(left<right){
                int mid=left+(right-left)/2;
                if(nums[mid]==target){
                    return mid;
                }else if(nums[mid]<target){
                    left=mid+1;
                }else if(nums[mid]>target){
                    right=mid;
                }


            }
            return -1;
        }
    }
}
